<#include "common/common.html"/>
<meta charset="UTF-8">
	<table
		     class="easyui-datagrid"   
		     id="datagrid"  
	         title="项目审核管理"  
	         url="${base}/project/list"
	         toolbar="#searchtool,#toolbar" 
	         pagination="true"
	         rownumbers="true" 
	         fitColumns="true"
	         singleSelect="true"
	         data-options="fit:false,border:false,pageSize:20,pageList:[5,10,15,20]" >   
	    <thead>  
	        <tr>
	            <th field="id" width="5%" checkbox="true"></th>  
	            <th field="projectNo" width="8%">项目编号</th> 
	            <th field="projectName" width="10%">项目标题</th>
	            <th field="industryStr" width="10%">所属行业</th>  
	            <th field="province" width="5%">地区</th> 
	            <th field="phone" width="8%">手机号</th> 
	            <th field="pusher" width="5%">发布人</th> 
	            <th field="total" width="5%">金额(万元)</th>
	            <th field="modeStr" width="5%">项目类型</th>            
	            <th field="projectStatusStr" width="5%">项目状态</th> 
	            <th field="authStr" width="5%">认证状态</th> 
	            <th field="pushtimeStr" width="5%">发布时间</th>  
	            <th field="userName" width="5%">操作员</th> 
	            <th field="insertTimeStr" width="5%">操作时间</th>
	            <th field="operate" width="15%" formatter="formatOper">操作</th>   	        
	        </tr>  
	    </thead>  
	</table>  
<div id="searchtool" style="padding:5px">  
      <span>所属行业:</span><input type="text" id="qryIndustryId" value="" sytle="width:200px" />&nbsp;&nbsp;  
      <span>所在地区:</span><input type="text" id="qryProvince" value="" sytle="width:200px" />&nbsp;&nbsp;  
      <span>项目状态:</span><input type="text" id="qryProjectStatus" value="" sytle="width:200px" />&nbsp;&nbsp; 
      <span>认证状态:</span><input type="text" id="qryAuth" value="" sytle="width:200px" />&nbsp;&nbsp;<br>  
      <span>起始时间:</span><input class="easyui-datebox" id="qryStartDate" value="" sytle="width:200px" />&nbsp;&nbsp;
      <span>截至时间:</span><input class="easyui-datebox" id="qryEndDate" value="" sytle="width:200px" />&nbsp;&nbsp; 
      <span>关键字&nbsp;&nbsp;&nbsp;:</span><input type="text" id="qryKeyword" value="" sytle="width:200px" data-options="prompt:'标题/发布人/编号'"/>&nbsp;&nbsp;
      <span>项目类型:</span><input type="text" id="qryMode" value="" sytle="width:200px" />&nbsp;&nbsp;
      <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" onclick="javascript:queryData({industryId:$('#qryIndustryId').combobox('getValue'),provincePostcode:$('#qryProvince').combobox('getValue')
    	  ,projectStatus:$('#qryProjectStatus').combobox('getValue'),auth:$('#qryAuth').combobox('getValue'),qryStartDate:$('#qryStartDate').datebox('getValue'),qryEndDate:$('#qryEndDate').datebox('getValue')
    	  ,qryKeyWord:$('#qryKeyword').val(),mode:$('#qryMode').combobox('getValue')});">搜索</a>  
</div> 
<div id="toolbar">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:doAudit('203');">发布</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-edit" plain="true" onclick="javascript:doAudit('204');">撤销</a>
</div>

<script type="text/javascript">
$(function () { 
	 
	 $('#qryIndustryId').combobox({   
         url:base+'/industry/queryAllForProject',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'id',     
         textField:'industryName',
         loadFilter:function(data){
			    data.unshift({id:'-1',industryName:'所有'});
			    return data;
		      }
         
      });  
	 
	 $('#qryProvince').combobox({   
         url:base+'/cityinfo/findAllProvince',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'postcode',     
         textField:'cityName'  ,
         loadFilter:function(data){
			    data.unshift({postcode:'-1',cityName:'所有'});
			    return data;
		      }
      });
	 
	 $('#qryProjectStatus').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=200',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName' ,
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
	 
	 $('#qryAuth').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=500',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName',
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
	 
	 $('#qryMode').combobox({   
         url:base+'/dictionary/getDictionaryByParentCode?parentCode=300',   
         editable:false, //不可编辑状态  
         cache: false,  
         //panelHeight: '150',//自动高度适合  
         valueField:'itemCode',     
         textField:'itemName',
         loadFilter:function(data){
			    data.unshift({itemCode:'-1',itemName:'所有'});
			    return data;
		      }
      });  
	 
	
});

function formatOper(val,row,index){
	var managePhotoUrl ="project/managePhoto?id="+row.id;
	var showUser = "<a href='javascript:showUser(\""+row.id+"\");'>显示关注人</a>";
	var managePhoto = "<a href='javascript:open(\""+managePhotoUrl+"\");'>|图集管理</a>";
	//发布状态下，图片管理不显示
	if(row.projectStatus == 203){
		managePhoto="";
	}
	return "<a href='javascript:showPreView("+row.id+")'>APP预览</a>"+"|"+showUser+managePhoto;
	
}
var $wins;
function showUser(id){
   var windowWidth =$(window.parent).width();
   var windowHeight=$(window.parent).height();
   var width= windowWidth-100;
   var height=windowHeight-200;
   var top=(windowHeight-height)/2;
   var left=(windowWidth-width)/2;
    $wins = $('#intentionDiv').window({
    	href: base+'/userStatistic/showUser?id='+id+'&noCache=random',
        title: '显示关注人',
        width: width,
        height: height,
        top: top,
        left: left,
        shadow: true,
        modal: true,
        iconCls: 'icon-add',
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });
    $('#datagrid').datagrid('clearSelections');
    $wins.window('open');
}

function showPreView(id){
	//alert('${mobileDomain}/projectApi/getProjectDetail?id='+id);
    var href= '${mobileDomain}/projectApi/getProjectDetailPreView?id='+id;
    var $win2 = $('#preView').window({
   	   content : '<iframe scrolling="yes" frameborder="0"  src="'  
              + href  
              + '" style="width:100%;height:98%;"></iframe>',  
        title: 'APP预览',
        width: 414,
        height: 736,
        top: ($(window).height() - 820) * 0.5,
        left: ($(window).width() - 450) * 0.5,
        shadow: true,
        modal: true,
        closed: true,
        minimizable: false,
        maximizable: false,
        collapsible: false
    });

    $win2.window('open');
}

function doAudit(status){
	var row = $('#datagrid').datagrid('getSelected');
    if ((row&&row.length==1) || (row&&row.length==undefined)){
    	var url = base+"/project/doaudit?id="+row.id+"&status="+status;
    	var alertStr = "";
    	if(203 == status){
    		alertStr = "确定要发布吗?"
    	}else if(204 == status){
    		alertStr = "确定要撤回吗?"
    	}
        $.messager.confirm('审核确认',alertStr,function(r){
            if (r){
                $.post(url,function(result){           	
                   $('#datagrid').datagrid('reload');   
                });
            }
        });
    }else{
    	$.messager.alert('提示','请选择一条数据进行操作','info');
    }
	
}

////////////////使用了Solr，不再需要缓存了，以下代码没用////////////////////////
var dictionaryArray =null;
function getDictionaryNameByCode(code,dictionaryArray){
	for(var index in dictionaryArray){
		var dic = dictionaryArray[index];
		if(dic.itemCode==code){
			return dic.itemName;
		}
	}
	return "";
}
function formatDictionary(code){
	var nameStr="";
	if(dictionaryArray){
		nameStr = getDictionaryNameByCode(code,dictionaryArray);
	}else{
	   console.log("第一次获得数据字典");
	   $.ajax( {    
	    url:'dictionary/listAll',
	    data:{    
	    	code : code  
	    },    
	    type:'post',    
	    cache:false, 
	    async: false,
	    dataType:'json',    
	    success:function(data) {
	    	dictionaryArray=data;
	    	nameStr = getDictionaryNameByCode(code,dictionaryArray);
	    },    
	     error : function() {    
	       console.log("error,formatDictionary");    
	    }    
	});  
	}
	return nameStr;
}

var industryArray = null;

function getIndustryNameById(id,industryArray){
	for(var index in industryArray){
		var industry = industryArray[index];
		if(industry.id==id){
			return industry.industryName;
		}
	}
	return "";
}
function formatIndustry(id){
	var nameStr="";
	if(industryArray){
		nameStr=getIndustryNameById(id,industryArray);
	}else{
	  console.log("第1次从获得行业列表~");
	  $.ajax( {    
	    url:baes+'/industry/queryAll',
	    data:{    
	    	id : id  
	    },    
	    type:'post',    
	    cache:false, 
	    async: false,
	    dataType:'json',    
	    success:function(data) {
	    	console.log(data);
	    	industryArray=data;
	    	nameStr=getIndustryNameById(id,industryArray);
	    },    
	     error : function() {    
	        console.log("formatIndustry error~");    
	    }    
	   });  
	}
	return nameStr;
}
</script>
